package com.qfedu.edu.seckill.orderservice.controller;

import com.qfedu.edu.seckill.bo.CreateOrderBack;
import com.qfedu.edu.seckill.bo.OrderShow;
import com.qfedu.edu.seckill.orderservice.service.IOrderService;
import com.qfedu.edu.seckill.result.R;
import com.qfedu.edu.seckill.vo.CreateOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @author xiaobobo
 * @title: OrderController
 * @projectName cd-java-2404-seckill-parent
 * @description: TODO
 * @date 2025/2/5  15:33
 */
@RestController
@RequestMapping("/orderservice/order")
@Slf4j
public class OrderController {

    @Autowired
    private IOrderService orderService;

    /**
     * 下订单的控制器
     * @param createOrderVo
     * @param request
     * @return
     */
   @PostMapping("/createOrder")
   public R createOrder(CreateOrderVo createOrderVo, HttpServletRequest request) throws UnsupportedEncodingException {
       log.info("创建订单的控制器执行了....");
       CreateOrderBack createOrderBack = orderService.createOrder(createOrderVo, request);
       return R.ok().data("orderNum",createOrderBack.getOrderNumber()).data("userId",createOrderBack.getUserId());
   }

    /**
     * 通过订单号查询订单信息
     * @param orderNumber
     * @return
     */
   @GetMapping("listOrderByOrderNumber")
   public R listOrderByOrderNumber(String orderNumber){
       OrderShow orderShow=orderService.listOrderByOrderNumber(orderNumber);
       return R.ok().data("order",orderShow);
   }


}
